﻿// ==UserScript==
// @name           taobaoke
// @namespace      taobaopp
// @description    显示淘宝客搜索中，店铺每周平均千次点击收入
// @include        http://taoke.alimama.com/spreader/search_sh_catalog.htm*
// ==/UserScript==
//GM_log("taobaoke");
var items = new Array();
var lv = document.getElementById('listview');
function page2(responseDetails)
{
	//alert(responseDetails.responseText);
	//<li><strong>每周平均千次点击收入：</strong><span>0.0元</span></li>
	var qds = responseDetails.responseText.match(/[\d.]+元/);
	//<li><strong>掌柜地址：</strong>广东深圳</li>
	var address = responseDetails.responseText.match(/掌柜地址：<\/strong>(.*?)<\/li>/)[1];
	//GM_log(qds);
	//掌柜名和图片 配对
	//<li><strong>掌柜：</strong><i>伊人女装</i>
	//var zg = responseDetails.responseText.match(/掌柜：<\/strong><i>(.+?)<\/i>/)[1];
	//GM_log(zg);
	//alert(zg+qds);	
	//http://logo.taobao.com/shop-logo/12/54/1254015ce61734ce1acec29cd68e2487_1192642041463.jpg" >
	//var logo = responseDetails.responseText.match(/(http:\/\/logo\.taobao\.com\/shop-logo\/.+?)"/)[1];
	var logo = responseDetails.responseText.match(/(http:\/\/logo\.taobao\.com\/shop-logo\/.+?)"/);
	if(logo == null)
	{
		//GM_log(responseDetails.responseText);
		GM_log('logo=null');
		GM_log(responseDetails.responseText);
		return;
	}
	else
		logo = logo[1];
	//GM_log(logo);
	for(var x in items)
	{
		if(items[x].innerHTML.match(logo))
		{	
			//alert(items[x].textContent);
			if(GM_getValue('thousandin',true))
				items[x].innerHTML +='<div title="每周平均千次点击收入">'+qds+'</div>';
			if(GM_getValue('address',true))
				items[x].innerHTML +='<div title="掌柜地址">'+address+'</div>';
			//GM_log();
			//GM_log('match');
			//GM_log(zg);
			//alert(zg);
			break;
		}
	}
	
}
function page1(responseDetails)
{
	//alert(responseDetails.responseText);
	var href = responseDetails.responseText.match(/http:\/\/store\.taobao\.com\/shop\/cps_shop_detail\.htm\?userid=\d+/);
	//GM_log(href);
	GM_xmlhttpRequest({method: 'GET',url: href[0],onload: page2});
}
function loading(responseDetails)
{
	if(lv.textContent.match(/店铺推广信息/) && lv.textContent.match(/每周平均千次点击收入/)==null )
	{
		//alert(document.getElementById('listview').textContent);
		//GM_log(responseDetails.statusText);
		//GM_log(responseDetails.responseHeaders);
		//alert('淘宝网');	
		lv.innerHTML += '<每周平均千次点击收入>';
		var list = document.evaluate("//div[@class='zck_list1']",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);	
		for (var i = 0; i < list.snapshotLength; i++) {
			var item = list.snapshotItem(i);
			items[i] = item;
			var href = item.childNodes[0].childNodes[1].childNodes[0].childNodes[3].childNodes[1].href;
			//GM_log(i);
			//GM_log(list.snapshotLength);
			GM_xmlhttpRequest({method: 'GET',url: href,onload: page1});
			//break;
		}
	}
}
document.addEventListener('load',loading, true);
